<template>
    <el-dialog
        v-model="routeRootPathDeleteDialogVisible"
        title="删除路由文根"
        width="20%"
        align-center
        :show-close="false"
        :close-on-click-modal="false"
    >
        是否确定删除？
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="cancelDialog()">取 消</el-button>
                <el-button type="primary" :loading="deleteLoading" @click="submitDialog()">
                    确认
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup name="DeleteRouteRootPathDialog" lang="ts">
import {routeRootPathInfoDelete, routeRootPathInfoQuery} from "@/request/routeRootPath";
import {ElNotification} from "element-plus";
import {componentInfoQueryNoContent} from "@/request/components";
import {computed, ref, defineProps} from "vue";
import {useRouteRootStore} from "@/stores/menu/routeRootPath";

const props = defineProps(['routeRootPathForm']);

let routeRootPathForm = computed(() => {return props["routeRootPathForm"]});

let deleteLoading = ref(false);

let routeRootPathDeleteDialogVisible = computed(() => {return useRouteRootStore().deleteDialog});
let routeRootPathSearchData = computed(() => {return useRouteRootStore().routeRootPathSearchData});

function cancelDialog() {
    useRouteRootStore().resetDeleteDialog(false);
}

function submitDialog() {
    deleteLoading.value = true
    routeRootPathInfoDelete(routeRootPathForm.value).then(result => {
        if (result["code"] === '200') {
            ElNotification({
                title: 'Success',
                message: result["message"],
                type: 'success'
            });
            routeRootPathInfoQuery(routeRootPathSearchData.value).then(res => {
                // 查询所有组件
                let param = {
                    pageInfo: {
                        pageIndex: 1,
                        pageSize: 10000
                    }
                }
                componentInfoQueryNoContent(param).then(info => {
                    // 根据componentId匹配数据
                    let resData = res.data["dataList"];
                    for (let i = 0; i < resData.length; i++) {
                        let data = resData[i];
                        let filterRes = info.data["dataList"].filter(res => res.id === data.componentId);
                        if (filterRes.length > 0) {
                            data.componentName = filterRes[0]["componentCnName"];
                        }
                    }
                    useRouteRootStore().resetRouteRootPathDataList(res.data);
                })
            })
            deleteLoading.value = false
            useRouteRootStore().resetDeleteDialog(false);
        }
    }).catch(res => {
        deleteLoading.value = false
    })
}
</script>

<style scoped lang="less">

</style>